package com.itcast.arrays;

import com.itcast.Array.Student;

import java.util.Arrays;
import java.util.Comparator;

public class Test8 {

    /*
        遇到小数怎么排序????
            使用Double.compare(小数1, 小数2) 得到一个int类型的比较结果!!!
     */
    public static void main(String[] args) {
        Student[] arr = {
                new Student("ddd", 19, 170.3, 50, 15),
                new Student("aaa", 18, 170, 65, 100),
                new Student("ccc", 15, 179.8, 55, 20),
                new Student("bbb", 17, 179.7, 70, 10),
                new Student("eee", 16, 180, 52, 90),
        };
        Arrays.sort(arr, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                /*if(o1.getHeight() - o2.getHeight() > 0){
                    return 1;
                }else if(o1.getHeight() - o2.getHeight() < 0){
                    return -1;
                }else{
                    return 0;
                }*/
                int result = Double.compare(o1.getHeight(), o2.getHeight());
                return result;
            }
        });
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }
}
